import 'package:enterprise_v6_app/app/components/custom_app_bar.dart';
import 'package:enterprise_v6_app/app/components/custom_refresh.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_title_chart_page.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/data/entities/application/Inventory_system/daily_inspection_checklist_entity.dart';
import 'package:enterprise_v6_app/app/modules/application/inventory_system/daily_inspection_checklist/daily_checklist/daily_checklist_controller.dart';

///检查项清单
class DailyChecklistPage extends StatelessWidget {
  DailyChecklistPage({super.key});

  final controller = Get.put(DailyChecklistController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
        init: controller,
        builder: (_) {
          return Scaffold(
            backgroundColor: AppColors.bg_color_grey,
            appBar: CustomAppBar(
              titleText: '检查项清单',
            ),
            body: Container(
              color: AppColors.bg_color_grey,
              padding: EdgeInsets.only(top: 12.w, right: 14.w, left: 14.w),
              child: Column(
                children: [
                  Expanded(
                      child: CustomEasyRefreshList<DailyInspectionChecklistEntity>(
                    key: controller.globalKey,
                    dataLoad: controller.checklist,
                    itemBuilder: (item, index) {
                      return CustomTitleChartPage(
                          title: item.riskName ?? '',
                          titleRightWidget: _getResult('${item.controllable}'),
                          child: Column(
                            children: [
                              Row(
                                children: [
                                  Text(
                                    '检查项内容：${item.checkContent ?? ''}',
                                    style: TextStyle(fontSize: 13.sp, fontWeight: FontWeight.w400, color: const Color(0xffA5A6B5)),
                                  ),
                                ],
                              ),
                            ],
                          ));
                    },
                  ))
                ],
              ),
            ),
          );
        });
  }

  // 落实结果  0待完成  1已完成
  Widget _getResult(String? i) {
    switch (i) {
      case '1':
        return _title('已完成', Colors.lightGreen);
      case '0':
        return _title('待完成', Colors.redAccent);
      default:
        return _title('未知', Colors.red);
    }
  }

  Widget _title(String title, Color color) {
    return Container(
      padding: EdgeInsets.symmetric(vertical: 2.w, horizontal: 11.w),
      decoration: BoxDecoration(
          color: color,
          borderRadius: const BorderRadius.only(
            topLeft: Radius.circular(10),
            topRight: Radius.circular(10),
            bottomRight: Radius.circular(10),
          )),
      child: Text(
        title,
        style: TextStyle(
          color: Colors.white,
          fontSize: 10.sp,
          fontWeight: FontWeight.w400,
        ),
      ),
    );
  }
}
